﻿namespace SubhadraSolutions.Sharp.Utils.Extensions
{
    using System.Collections.Generic;

    using SubhadraSolutions.Sharp.Utils.Collections.Concurrent;
    using SubhadraSolutions.Sharp.Utils.Collections.Generic;
    using SubhadraSolutions.Sharp.Utils.Threading;

    public static class MainExtensions
    {
        /// <summary>
        /// Applies the thread safety decorator.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list">The list.</param>
        /// <returns></returns>
        public static SafeListDecorator<T> ApplyThreadSafetyDecorator<T>(this IList<T> list)
        {
            return new SafeListDecorator<T>(list);
        }

        /// <summary>
        /// Applies the thread safety decorator.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="collection">The collection.</param>
        /// <returns></returns>
        public static SafeCollectionDecorator<T> ApplyThreadSafetyDecorator<T>(this ICollection<T> collection)
        {
            return new SafeCollectionDecorator<T>(collection);
        }

        /// <summary>
        /// Adapts for notify collection changed.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list">The list.</param>
        /// <returns></returns>
        public static ListNotifyCollectionChangedAdapter<T> AdaptForNotifyCollectionChanged<T>(this IList<T> list)
        {
            return new ListNotifyCollectionChangedAdapter<T>(list);
        }

        /// <summary>
        /// Adapts for dispatcher aware notify collection changed adapter.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="list">The list.</param>
        /// <param name="dispatcherProvider">The dispatcher provider.</param>
        /// <returns></returns>
        public static DispatcherAwareListNotifyCollectionChangedAdapter<T> AdaptForDispatcherAwareNotifyCollectionChangedAdapter<T>(this IList<T> list, IDispatcherProvider dispatcherProvider)
        {
            return new DispatcherAwareListNotifyCollectionChangedAdapter<T>(list, dispatcherProvider);
        }

        /// <summary>
        /// Filters the duplicates.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumerable">The enumerable.</param>
        /// <returns></returns>
        public static IEnumerable<T> FilterDuplicates<T>(this IEnumerable<T> enumerable)
        {
            return new DuplicatesFilteredEnumerable<T>(enumerable);
        }

        /// <summary>
        /// Filters the duplicates.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="enumerator">The enumerator.</param>
        /// <returns></returns>
        public static IEnumerator<T> FilterDuplicates<T>(this IEnumerator<T> enumerator)
        {
            return new DuplicatesFilteredEnumerator<T>(enumerator);
        }
    }
}
